package com.oa.modules.approvalsec1.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oa.common.utils.R;
import com.oa.modules.approvalsec1.entity.MattersEntity;
import com.oa.modules.approvalsec1.service.MattersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Hankaicheng
 * @Date: 2022/5/5 14:20
 */
@RequestMapping("/matters")
@RestController
@Api(tags = "服务事项相关接口")
public class MattersController {

    @Autowired
    private MattersService mattersService;

    @ApiOperation("树状列表")
    @GetMapping("/treeList")
    public R treeList() {
        List<MattersEntity> mattersList = mattersService.list(new QueryWrapper<MattersEntity>().eq("parentid", 0));
        mattersList.forEach(item -> {
            List<MattersEntity> childList = mattersService.list(new QueryWrapper<MattersEntity>().eq("parentid", item.getId()));
            item.setChildren(childList);
        });
        return R.ok().put("data", mattersList);
    }

}
